﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using CapturePanorama.Internals;
using UnityEngine;

namespace CapturePanorama
{
	// Token: 0x02000004 RID: 4
	public class CapturePanorama : MonoBehaviour
	{
		// Token: 0x17000001 RID: 1
		// (get) Token: 0x0600000F RID: 15 RVA: 0x00002A67 File Offset: 0x00000C67
		public CapturePanorama.ImageFormat imageFormat
		{
			get
			{
				return this._imageFormat;
			}
		}

		// Token: 0x17000002 RID: 2
		// (get) Token: 0x06000010 RID: 16 RVA: 0x00002A6F File Offset: 0x00000C6F
		public int PanoramaWidth
		{
			get
			{
				return this.panoramaWidth;
			}
		}

		// Token: 0x17000003 RID: 3
		// (get) Token: 0x06000011 RID: 17 RVA: 0x00002A77 File Offset: 0x00000C77
		public CapturePanorama.AntiAliasing antiAliasing
		{
			get
			{
				return this._antiAliasing;
			}
		}

		// Token: 0x17000004 RID: 4
		// (get) Token: 0x06000012 RID: 18 RVA: 0x00002A7F File Offset: 0x00000C7F
		public bool UseGpuTransform
		{
			get
			{
				return this.useGpuTransform;
			}
		}

		// Token: 0x17000005 RID: 5
		// (get) Token: 0x06000013 RID: 19 RVA: 0x00002A87 File Offset: 0x00000C87
		public bool FadeDuringCapture
		{
			get
			{
				return this.fadeDuringCapture;
			}
		}

		// Token: 0x06000014 RID: 20 RVA: 0x00002A8F File Offset: 0x00000C8F
		private System.Drawing.Imaging.ImageFormat FormatToDrawingFormat(CapturePanorama.ImageFormat format)
		{
			switch (format)
			{
			case CapturePanorama.ImageFormat.PNG:
				return System.Drawing.Imaging.ImageFormat.Png;
			case CapturePanorama.ImageFormat.JPEG:
				return System.Drawing.Imaging.ImageFormat.Jpeg;
			case CapturePanorama.ImageFormat.BMP:
				return System.Drawing.Imaging.ImageFormat.Bmp;
			default:
				return System.Drawing.Imaging.ImageFormat.Png;
			}
		}

		// Token: 0x06000015 RID: 21 RVA: 0x00002ABF File Offset: 0x00000CBF
		private string FormatMimeType(CapturePanorama.ImageFormat format)
		{
			switch (format)
			{
			case CapturePanorama.ImageFormat.PNG:
				return "image/png";
			case CapturePanorama.ImageFormat.JPEG:
				return "image/jpeg";
			case CapturePanorama.ImageFormat.BMP:
				return "image/bmp";
			default:
				return string.Empty;
			}
		}

		// Token: 0x06000016 RID: 22 RVA: 0x00002AEF File Offset: 0x00000CEF
		private string FormatToExtension(CapturePanorama.ImageFormat format)
		{
			switch (format)
			{
			case CapturePanorama.ImageFormat.PNG:
				return "png";
			case CapturePanorama.ImageFormat.JPEG:
				return "jpg";
			case CapturePanorama.ImageFormat.BMP:
				return "bmp";
			default:
				return string.Empty;
			}
		}

		// Token: 0x06000017 RID: 23 RVA: 0x00002B1F File Offset: 0x00000D1F
		public void Awake()
		{
			if (CapturePanorama.instance == null)
			{
				CapturePanorama.instance = this;
			}
			else
			{
				UnityEngine.Debug.LogError("More than one CapturePanorama instance detected.");
			}
		}

		// Token: 0x06000018 RID: 24 RVA: 0x00002B46 File Offset: 0x00000D46
		public void Start()
		{
			this.audioSource = base.gameObject.AddComponent<AudioSource>();
			this.audioSource.spatialBlend = 0f;
			this.audioSource.Play();
			this.Reinitialize();
		}

		// Token: 0x06000019 RID: 25 RVA: 0x00002B7A File Offset: 0x00000D7A
		private float IpdScaleFunction(float latitudeNormalized)
		{
			return 1.5819767f * Mathf.Exp(-latitudeNormalized * latitudeNormalized) - 0.5819767f;
		}

		// Token: 0x0600001A RID: 26 RVA: 0x00002B91 File Offset: 0x00000D91
		public void OnDestroy()
		{
			this.Cleanup();
		}

		// Token: 0x0600001B RID: 27 RVA: 0x00002B9C File Offset: 0x00000D9C
		private void Cleanup()
		{
			this.faces = null;
			UnityEngine.Object.Destroy(this.copyCameraScript);
			UnityEngine.Object.Destroy(this.cam);
			if (this.camGos != null)
			{
				for (int i = this.camGos.Length - 1; i >= 0; i--)
				{
					if (this.camGos[i] != null)
					{
						UnityEngine.Object.Destroy(this.camGos[i]);
					}
				}
			}
			this.camGos = null;
			this.numCameras = -1;
			this.hFov = (this.vFov = -1f);
			if (this.cubemapRenderTexture != null)
			{
				UnityEngine.Object.Destroy(this.cubemapRenderTexture);
			}
			this.cubemapRenderTexture = null;
			this.convertPanoramaKernelIdx = (this.renderStereoIdx = (this.textureToBufferIdx = -1));
			this.convertPanoramaKernelIdxs = null;
			this.resultPixels = (this.cameraPixels = null);
			if (this.forceWaitTexture != null)
			{
				UnityEngine.Object.Destroy(this.forceWaitTexture);
			}
			this.forceWaitTexture = new Texture2D(1, 1);
		}

		// Token: 0x0600001C RID: 28 RVA: 0x00002CAC File Offset: 0x00000EAC
		private void Reinitialize()
		{
			try
			{
				this.ReinitializeBody();
			}
			catch (Exception)
			{
				this.Cleanup();
				throw;
			}
		}

		// Token: 0x0600001D RID: 29 RVA: 0x00002CE0 File Offset: 0x00000EE0
		private void ReinitializeBody()
		{
			this.Log("Settings changed, calling Reinitialize()");
			this.initializeFailed = true;
			if (!SystemInfo.supportsComputeShaders)
			{
				UnityEngine.Debug.LogWarning("CapturePanorama requires compute shaders. Your system does not support them. On PC, compute shaders require DirectX 11, Windows Vista or later, and a GPU capable of Shader Model 5.0.");
				return;
			}
			this.startSound = (AudioClip)Resources.Load("Sound/CapturePanorama/Clicks_13");
			this.doneSound = (AudioClip)Resources.Load("Sound/CapturePanorama/Xylo_13");
			this.failSound = (AudioClip)Resources.Load("Sound/CapturePanorama/DistClickBlocked1");
			this.fadeMaterial = (Material)Resources.Load("Material/CapturePanorama/Fade material");
			this.convertPanoramaShader = (ComputeShader)Resources.Load("ComputeShaders/ConvertPanoramaShader");
			this.convertPanoramaStereoShader = (ComputeShader)Resources.Load("ComputeShaders/ConvertPanoramaStereoShader");
			this.textureToBufferShader = (ComputeShader)Resources.Load("ComputeShaders/TextureToBufferShader");
			this.SetImageFormat(GlobalPreferences.ImageFormat.value);
			this.SetImageWidth(GlobalPreferences.ImageWidth.value);
			this.UseGpu(GlobalPreferences.UseGpu.value);
			this.UseFade(GlobalPreferences.UseFade.value);
			this.lastConfiguredCaptureStereoscopic = this.captureStereoscopic;
			this.lastConfiguredPanoramaWidth = this.panoramaWidth;
			this.lastConfiguredInterpupillaryDistance = this.interpupillaryDistance;
			this.lastConfiguredNumCirclePoints = this.numCirclePoints;
			this.lastConfiguredSsaaFactor = this.ssaaFactor;
			this.lastConfiguredAntiAliasing = this._antiAliasing;
			this.lastConfiguredSaveCubemap = this.saveCubemap;
			this.lastConfiguredUseGpuTransform = this.useGpuTransform;
			this.Cleanup();
			CubemapFace[] array = new CubemapFace[6];
			RuntimeHelpers.InitializeArray(array, fieldof(<PrivateImplementationDetails>.$field-DB17E883A647963A26D973378923EF4649801319).FieldHandle);
			this.faces = array;
			for (int i = 0; i < this.faces.Length; i++)
			{
			}
			this.panoramaHeight = this.panoramaWidth / 2;
			this.camGos = new GameObject[3];
			for (int j = 0; j < 3; j++)
			{
				this.camGos[j] = new GameObject("PanoramaCaptureCamera" + j);
				this.camGos[j].hideFlags = HideFlags.HideAndDontSave;
				if (j > 0)
				{
					this.camGos[j].transform.parent = this.camGos[j - 1].transform;
				}
			}
			this.camGos[2].AddComponent<Camera>();
			this.cam = this.camGos[2].GetComponent<Camera>();
			this.cam.enabled = false;
			this.camGos[2].AddComponent<ImageEffectCopyCamera>();
			this.copyCameraScript = this.camGos[2].GetComponent<ImageEffectCopyCamera>();
			this.copyCameraScript.enabled = false;
			this.numCameras = this.faces.Length;
			this.hFov = (this.vFov = 90f);
			if (this.captureStereoscopic)
			{
				float num = 360f / (float)this.numCirclePoints;
				float num2 = 0.001f;
				float b = 2f * (1.5707964f - Mathf.Acos(this.IpdScaleFunction(0.5f))) * 360f / 6.2831855f;
				this.hFov = Mathf.Max(90f + num, b) + num2;
				this.vFov = 90f;
				this.numCameras = 2 + this.numCirclePoints * 4;
				this.circleRadius = this.interpupillaryDistance / 2f;
				this.hFovAdjustDegrees = this.hFov / 2f;
				this.vFovAdjustDegrees = this.vFov / 2f;
			}
			double num3 = (double)this.panoramaWidth * 90.0 / 360.0;
			this.cameraWidth = (int)Math.Ceiling(Math.Tan((double)(this.hFov * 6.2831855f / 360f / 2f)) * num3 * (double)this.ssaaFactor);
			this.cameraHeight = (int)Math.Ceiling(Math.Tan((double)(this.vFov * 6.2831855f / 360f / 2f)) * num3 * (double)this.ssaaFactor);
			this.Log("Number of cameras: " + this.numCameras);
			this.Log(string.Concat(new object[]
			{
				"Camera dimensions: ",
				this.cameraWidth,
				"x",
				this.cameraHeight
			}));
			this.usingGpuTransform = (this.useGpuTransform && this.convertPanoramaShader != null);
			this.cubemapRenderTexture = new RenderTexture(this.cameraWidth, this.cameraHeight, 24, RenderTextureFormat.ARGB32);
			this.cubemapRenderTexture.antiAliasing = (int)this._antiAliasing;
			this.cubemapRenderTexture.Create();
			if (this.usingGpuTransform)
			{
				this.convertPanoramaKernelIdx = this.convertPanoramaShader.FindKernel("CubeMapToEquirectangular");
				this.convertPanoramaYPositiveKernelIdx = this.convertPanoramaShader.FindKernel("CubeMapToEquirectangularPositiveY");
				this.convertPanoramaYNegativeKernelIdx = this.convertPanoramaShader.FindKernel("CubeMapToEquirectangularNegativeY");
				this.convertPanoramaKernelIdxs = new int[]
				{
					this.convertPanoramaKernelIdx,
					this.convertPanoramaYPositiveKernelIdx,
					this.convertPanoramaYNegativeKernelIdx
				};
				this.convertPanoramaShader.SetInt("equirectangularWidth", this.panoramaWidth);
				this.convertPanoramaShader.SetInt("equirectangularHeight", this.panoramaHeight);
				this.convertPanoramaShader.SetInt("ssaaFactor", this.ssaaFactor);
				this.convertPanoramaShader.SetInt("cameraWidth", this.cameraWidth);
				this.convertPanoramaShader.SetInt("cameraHeight", this.cameraHeight);
				int num4 = (this.panoramaHeight + 8 - 1) / 8;
				int num5 = this.panoramaWidth;
				int num6 = (!this.captureStereoscopic) ? num4 : (2 * this.panoramaHeight);
				this.resultPixels = new uint[num5 * num6 + 1];
			}
			this.textureToBufferIdx = this.textureToBufferShader.FindKernel("TextureToBuffer");
			this.textureToBufferShader.SetInt("width", this.cameraWidth);
			this.textureToBufferShader.SetInt("height", this.cameraHeight);
			this.textureToBufferShader.SetFloat("gamma", (QualitySettings.activeColorSpace != ColorSpace.Linear) ? 1f : 0.45454544f);
			this.renderStereoIdx = this.convertPanoramaStereoShader.FindKernel("RenderStereo");
			if ((this.saveCubemap || !this.usingGpuTransform) && (this.cameraPixels == null || this.cameraPixels.Length != this.numCameras * this.cameraWidth * this.cameraHeight))
			{
				this.cameraPixels = new uint[this.numCameras * this.cameraWidth * this.cameraHeight + 1];
			}
			this.tanHalfHFov = Mathf.Tan(this.hFov * 6.2831855f / 360f / 2f);
			this.tanHalfVFov = Mathf.Tan(this.vFov * 6.2831855f / 360f / 2f);
			this.hFovAdjust = this.hFovAdjustDegrees * 6.2831855f / 360f;
			this.vFovAdjust = this.vFovAdjustDegrees * 6.2831855f / 360f;
			if (this.captureStereoscopic && this.usingGpuTransform)
			{
				this.convertPanoramaStereoShader.SetFloat("tanHalfHFov", this.tanHalfHFov);
				this.convertPanoramaStereoShader.SetFloat("tanHalfVFov", this.tanHalfVFov);
				this.convertPanoramaStereoShader.SetFloat("hFovAdjust", this.hFovAdjust);
				this.convertPanoramaStereoShader.SetFloat("vFovAdjust", this.vFovAdjust);
				this.convertPanoramaStereoShader.SetFloat("interpupillaryDistance", this.interpupillaryDistance);
				this.convertPanoramaStereoShader.SetFloat("circleRadius", this.circleRadius);
				this.convertPanoramaStereoShader.SetInt("numCirclePoints", this.numCirclePoints);
				this.convertPanoramaStereoShader.SetInt("equirectangularWidth", this.panoramaWidth);
				this.convertPanoramaStereoShader.SetInt("equirectangularHeight", this.panoramaHeight);
				this.convertPanoramaStereoShader.SetInt("cameraWidth", this.cameraWidth);
				this.convertPanoramaStereoShader.SetInt("cameraHeight", this.cameraHeight);
				this.convertPanoramaStereoShader.SetInt("ssaaFactor", this.ssaaFactor);
			}
			this.initializeFailed = false;
		}

		// Token: 0x0600001E RID: 30 RVA: 0x00003507 File Offset: 0x00001707
		private void Log(string s)
		{
			if (this.enableDebugging)
			{
				UnityEngine.Debug.Log(s, this);
			}
		}

		// Token: 0x0600001F RID: 31 RVA: 0x0000351C File Offset: 0x0000171C
		public void Update()
		{
			bool flag = false;
			if (this.initializeFailed || this.panoramaWidth < 4 || (this.captureStereoscopic && this.numCirclePoints < 8))
			{
				if (flag)
				{
					if (this.panoramaWidth < 4)
					{
						UnityEngine.Debug.LogError("Panorama Width must be at least 4. No panorama captured.");
					}
					if (this.captureStereoscopic && this.numCirclePoints < 8)
					{
						UnityEngine.Debug.LogError("Num Circle Points must be at least 8. No panorama captured.");
					}
					if (this.initializeFailed)
					{
						UnityEngine.Debug.LogError("Initialization of Capture Panorama script failed. Cannot capture content.");
					}
					if (this.failSound != null && Camera.main != null)
					{
						this.audioSource.PlayOneShot(this.failSound);
					}
				}
				return;
			}
			if (this.captureStereoscopic != this.lastConfiguredCaptureStereoscopic || this.panoramaWidth != this.lastConfiguredPanoramaWidth || this.interpupillaryDistance != this.lastConfiguredInterpupillaryDistance || this.numCirclePoints != this.lastConfiguredNumCirclePoints || this.ssaaFactor != this.lastConfiguredSsaaFactor || this.antiAliasing != this.lastConfiguredAntiAliasing || this.saveCubemap != this.lastConfiguredSaveCubemap || this.useGpuTransform != this.lastConfiguredUseGpuTransform)
			{
				this.Reinitialize();
			}
		}

		// Token: 0x06000020 RID: 32 RVA: 0x0000366C File Offset: 0x0000186C
		public void CaptureScreenshotSync(string filenameBase)
		{
			IEnumerator enumerator = this.CaptureScreenshotAsyncHelper(filenameBase, false);
			while (enumerator.MoveNext())
			{
			}
		}

		// Token: 0x06000021 RID: 33 RVA: 0x00003692 File Offset: 0x00001892
		public void CaptureScreenshotAsync(string filenameBase)
		{
			base.StartCoroutine(this.CaptureScreenshotAsyncHelper(filenameBase, true));
		}

		// Token: 0x06000022 RID: 34 RVA: 0x000036A3 File Offset: 0x000018A3
		public void CaptureScreenshotAsync(string filePath, string filenameBase)
		{
			this.saveImagePath = filePath;
			base.StartCoroutine(this.CaptureScreenshotAsyncHelper(filenameBase, true));
		}

		// Token: 0x06000023 RID: 35 RVA: 0x000036BC File Offset: 0x000018BC
		private void SetFadersEnabled(IEnumerable<ScreenFadeControl> fadeControls, bool value)
		{
			foreach (ScreenFadeControl screenFadeControl in fadeControls)
			{
				screenFadeControl.enabled = value;
			}
		}

		// Token: 0x06000024 RID: 36 RVA: 0x00003710 File Offset: 0x00001910
		public IEnumerator FadeOut(IEnumerable<ScreenFadeControl> fadeControls)
		{
			this.Log("Doing fade out");
			float elapsedTime = 0f;
			UnityEngine.Color color = this.fadeColor;
			color.a = 0f;
			this.fadeMaterial.color = color;
			this.SetFadersEnabled(fadeControls, true);
			while (elapsedTime < this.fadeTime)
			{
				yield return new WaitForEndOfFrame();
				elapsedTime += Time.deltaTime;
				color.a = Mathf.Clamp01(elapsedTime / this.fadeTime);
				this.fadeMaterial.color = color;
			}
			yield break;
		}

		// Token: 0x06000025 RID: 37 RVA: 0x00003734 File Offset: 0x00001934
		public IEnumerator FadeIn(IEnumerable<ScreenFadeControl> fadeControls)
		{
			this.Log("Fading back in");
			float elapsedTime = 0f;
			UnityEngine.Color color2 = this.fadeColor;
			this.fadeMaterial.color = color2;
			UnityEngine.Color color = color2;
			while (elapsedTime < this.fadeTime)
			{
				yield return new WaitForEndOfFrame();
				elapsedTime += Time.deltaTime;
				color.a = 1f - Mathf.Clamp01(elapsedTime / this.fadeTime);
				this.fadeMaterial.color = color;
			}
			this.SetFadersEnabled(fadeControls, false);
			yield break;
		}

		// Token: 0x06000026 RID: 38 RVA: 0x00003758 File Offset: 0x00001958
		public IEnumerator CaptureScreenshotAsyncHelper(string filenameBase, bool async)
		{
			CapturePanorama.<CaptureScreenshotAsyncHelper>c__Iterator2.<CaptureScreenshotAsyncHelper>c__AnonStoreyD <CaptureScreenshotAsyncHelper>c__AnonStoreyD = new CapturePanorama.<CaptureScreenshotAsyncHelper>c__Iterator2.<CaptureScreenshotAsyncHelper>c__AnonStoreyD();
			<CaptureScreenshotAsyncHelper>c__AnonStoreyD.<>f__ref$2 = this;
			if (async)
			{
				while (this.Capturing)
				{
					yield return null;
				}
			}
			this.Capturing = true;
			if (!this.OnCaptureStart())
			{
				this.audioSource.PlayOneShot(this.failSound);
				this.Capturing = false;
				yield break;
			}
			Camera[] cameras = this.GetCaptureCameras();
			Array.Sort<Camera>(cameras, (Camera x, Camera y) => x.depth.CompareTo(y.depth));
			if (cameras.Length == 0)
			{
				UnityEngine.Debug.LogWarning("No cameras found to capture");
				this.audioSource.PlayOneShot(this.failSound);
				this.Capturing = false;
				yield break;
			}
			if (this._antiAliasing != CapturePanorama.AntiAliasing._1)
			{
				foreach (Camera camera in cameras)
				{
					if (camera.actualRenderingPath == RenderingPath.DeferredLighting || camera.actualRenderingPath == RenderingPath.DeferredShading)
					{
						UnityEngine.Debug.LogWarning("CapturePanorama: Setting Anti Aliasing=1 because at least one camera in deferred mode. Use SSAA setting or Antialiasing image effect if needed.");
						this._antiAliasing = CapturePanorama.AntiAliasing._1;
						this.Reinitialize();
						break;
					}
				}
			}
			this.Log("Starting panorama capture");
			if (this.startSound != null && Camera.main != null)
			{
				this.audioSource.PlayOneShot(this.startSound);
			}
			List<ScreenFadeControl> fadeControls = new List<ScreenFadeControl>();
			foreach (Camera camera2 in Camera.allCameras)
			{
				if (camera2.isActiveAndEnabled && camera2.targetTexture == null)
				{
					ScreenFadeControl screenFadeControl = camera2.gameObject.AddComponent<ScreenFadeControl>();
					screenFadeControl.fadeMaterial = this.fadeMaterial;
					fadeControls.Add(screenFadeControl);
				}
			}
			this.SetFadersEnabled(fadeControls, false);
			if (this.fadeDuringCapture && async)
			{
				yield return base.StartCoroutine(this.FadeOut(fadeControls));
			}
			for (int i = 0; i < 2; i++)
			{
				yield return new WaitForEndOfFrame();
			}
			ComputeBuffer convertPanoramaResultBuffer = null;
			ComputeBuffer forceWaitResultConvertPanoramaStereoBuffer = null;
			if (this.usingGpuTransform)
			{
				if (this.captureStereoscopic)
				{
					convertPanoramaResultBuffer = new ComputeBuffer(this.panoramaWidth * this.panoramaHeight * 2 + 1, 4);
					this.convertPanoramaStereoShader.SetBuffer(this.renderStereoIdx, "result", convertPanoramaResultBuffer);
					forceWaitResultConvertPanoramaStereoBuffer = new ComputeBuffer(1, 4);
					this.convertPanoramaStereoShader.SetBuffer(this.renderStereoIdx, "forceWaitResultBuffer", forceWaitResultConvertPanoramaStereoBuffer);
				}
				else
				{
					int num = (this.panoramaHeight + 8 - 1) / 8;
					convertPanoramaResultBuffer = new ComputeBuffer(this.panoramaWidth * num + 1, 4);
					foreach (int kernelIndex in this.convertPanoramaKernelIdxs)
					{
						this.convertPanoramaShader.SetBuffer(kernelIndex, "result", convertPanoramaResultBuffer);
					}
				}
			}
			int cameraPixelsBufferNumTextures = this.numCameras;
			this.overlapTextures = 0;
			int circlePointCircularBufferSize = 0;
			if (this.captureStereoscopic && this.usingGpuTransform)
			{
				this.overlapTextures = ((this.ssaaFactor != 1) ? 2 : 1);
				circlePointCircularBufferSize = 1 + this.overlapTextures;
				cameraPixelsBufferNumTextures = Math.Min(this.numCameras, 2 + 2 * circlePointCircularBufferSize);
			}
			ComputeBuffer cameraPixelsBuffer = new ComputeBuffer(cameraPixelsBufferNumTextures * this.cameraWidth * this.cameraHeight + 1, 4);
			this.textureToBufferShader.SetBuffer(this.textureToBufferIdx, "result", cameraPixelsBuffer);
			this.textureToBufferShader.SetInt("sentinelIdx", cameraPixelsBuffer.count - 1);
			if (this.usingGpuTransform && !this.captureStereoscopic)
			{
				this.convertPanoramaShader.SetInt("cameraPixelsSentinelIdx", cameraPixelsBuffer.count - 1);
				this.convertPanoramaShader.SetInt("sentinelIdx", convertPanoramaResultBuffer.count - 1);
				foreach (int kernelIndex2 in this.convertPanoramaKernelIdxs)
				{
					this.convertPanoramaShader.SetBuffer(kernelIndex2, "cameraPixels", cameraPixelsBuffer);
				}
			}
			if (this.usingGpuTransform && this.captureStereoscopic)
			{
				this.convertPanoramaStereoShader.SetInt("cameraPixelsSentinelIdx", cameraPixelsBuffer.count - 1);
				this.convertPanoramaStereoShader.SetBuffer(this.renderStereoIdx, "cameraPixels", cameraPixelsBuffer);
			}
			ComputeBuffer forceWaitResultTextureToBufferBuffer = new ComputeBuffer(1, 4);
			this.textureToBufferShader.SetBuffer(this.textureToBufferIdx, "forceWaitResultBuffer", forceWaitResultTextureToBufferBuffer);
			float startTime = Time.realtimeSinceStartup;
			Quaternion headOrientation = Quaternion.identity;
			this.Log("Rendering camera views");
			foreach (Camera camera3 in cameras)
			{
				this.Log("Camera name: " + camera3.gameObject.name);
			}
			Dictionary<Camera, List<ImageEffectCopyCamera.InstanceMethodPair>> methodMap = new Dictionary<Camera, List<ImageEffectCopyCamera.InstanceMethodPair>>();
			foreach (Camera camera4 in cameras)
			{
				methodMap[camera4] = ImageEffectCopyCamera.GenerateMethodList(camera4);
			}
			string suffix = "." + this.FormatToExtension(this._imageFormat);
			<CaptureScreenshotAsyncHelper>c__AnonStoreyD.filePath = string.Empty;
			string imagePath = this.saveImagePath;
			if (imagePath == null || imagePath == string.Empty)
			{
				imagePath = Application.dataPath + "/..";
			}
			this.convertPanoramaStereoShader.SetInt("circlePointCircularBufferSize", circlePointCircularBufferSize);
			int nextCirclePointCircularBufferStart = 0;
			int nextCirclePointStart = 0;
			int writeIdx = 0;
			int ilimit = (!this.usingGpuTransform) ? this.numCameras : (this.numCameras + this.overlapTextures * 4);
			int leftRightPhaseEnd = (ilimit - 2) / 2 + 2;
			int circlePointsRendered = 0;
			int saveCubemapImageNum = 0;
			this.Log("Changing quality level");
			int saveQualityLevel = QualitySettings.GetQualityLevel();
			bool qualitySettingWasChanged = false;
			string[] qualitySettingNames = QualitySettings.names;
			if (this.qualitySetting != qualitySettingNames[saveQualityLevel])
			{
				for (int num4 = 0; num4 < qualitySettingNames.Length; num4++)
				{
					string a = qualitySettingNames[num4];
					if (a == this.qualitySetting)
					{
						QualitySettings.SetQualityLevel(num4, false);
						qualitySettingWasChanged = true;
					}
				}
				if (!(this.qualitySetting != string.Empty) || !qualitySettingWasChanged)
				{
				}
			}
			this.BeforeRenderPanorama();
			RenderTexture.active = null;
			for (int num5 = 0; num5 < ilimit; num5++)
			{
				if (this.captureStereoscopic)
				{
					if (num5 < 2)
					{
						this.camGos[1].transform.localPosition = Vector3.zero;
						this.camGos[1].transform.localRotation = Quaternion.Euler((num5 != 0) ? -90f : 90f, 0f, 0f);
					}
					else
					{
						int num6;
						int num7;
						if (num5 < leftRightPhaseEnd)
						{
							num6 = num5 - 2;
							num7 = 0;
						}
						else
						{
							num6 = num5 - leftRightPhaseEnd;
							num7 = 2;
						}
						int num8 = num6 / 2 % this.numCirclePoints;
						int num9 = num6 % 2 + num7;
						float num10 = 360f * (float)num8 / (float)this.numCirclePoints;
						this.camGos[1].transform.localPosition = Quaternion.Euler(0f, num10, 0f) * Vector3.forward * this.circleRadius;
						if (num9 < 2)
						{
							this.camGos[1].transform.localRotation = Quaternion.Euler(0f, num10 + ((num9 != 0) ? this.hFovAdjustDegrees : (-this.hFovAdjustDegrees)), 0f);
						}
						else
						{
							this.camGos[1].transform.localRotation = Quaternion.Euler((num9 != 2) ? this.vFovAdjustDegrees : (-this.vFovAdjustDegrees), num10, 0f);
						}
						if (num9 == 1 || num9 == 3)
						{
							circlePointsRendered++;
						}
					}
				}
				else
				{
					switch (num5)
					{
					case 0:
						this.camGos[1].transform.localRotation = Quaternion.Euler(0f, 90f, 0f);
						break;
					case 1:
						this.camGos[1].transform.localRotation = Quaternion.Euler(0f, -90f, 0f);
						break;
					case 2:
						this.camGos[1].transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
						break;
					case 3:
						this.camGos[1].transform.localRotation = Quaternion.Euler(-90f, 0f, 0f);
						break;
					case 4:
						this.camGos[1].transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
						break;
					case 5:
						this.camGos[1].transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
						break;
					}
				}
				foreach (Camera camera5 in cameras)
				{
					this.camGos[2].transform.parent = null;
					this.cam.CopyFrom(camera5);
					this.camGos[0].transform.localPosition = this.cam.transform.localPosition;
					this.camGos[0].transform.localRotation = this.cam.transform.localRotation;
					this.camGos[2].transform.parent = this.camGos[1].transform;
					this.cam.transform.localPosition = Vector3.zero;
					this.cam.transform.localRotation = Quaternion.identity;
					this.copyCameraScript.enabled = (methodMap[camera5].Count > 0);
					this.copyCameraScript.onRenderImageMethods = methodMap[camera5];
					this.cam.fieldOfView = this.vFov;
					this.camGos[0].transform.rotation *= Quaternion.Inverse(headOrientation);
					if (this.useDefaultOrientation)
					{
						this.camGos[0].transform.rotation = Quaternion.identity;
					}
					this.cam.targetTexture = this.cubemapRenderTexture;
					this.cam.ResetAspect();
					Vector3 position = camera5.transform.position;
					Quaternion rotation = camera5.transform.rotation;
					float fieldOfView = camera5.fieldOfView;
					RenderTexture targetTexture = camera5.targetTexture;
					camera5.transform.position = this.cam.transform.position;
					camera5.transform.rotation = this.cam.transform.rotation;
					camera5.fieldOfView = this.cam.fieldOfView;
					this.cam.Render();
					camera5.transform.position = position;
					camera5.transform.rotation = rotation;
					camera5.fieldOfView = fieldOfView;
					camera5.targetTexture = targetTexture;
				}
				RenderTexture.active = this.cubemapRenderTexture;
				this.forceWaitTexture.ReadPixels(new Rect((float)(this.cameraWidth - 1), (float)(this.cameraHeight - 1), 1f, 1f), 0, 0);
				int num12 = 1000000 + num5;
				this.textureToBufferShader.SetInt("forceWaitValue", num12);
				this.textureToBufferShader.SetTexture(this.textureToBufferIdx, "source", this.cubemapRenderTexture);
				this.textureToBufferShader.SetInt("startIdx", writeIdx * this.cameraWidth * this.cameraHeight);
				this.textureToBufferShader.Dispatch(this.textureToBufferIdx, (this.cameraWidth + this.threadsX - 1) / this.threadsX, (this.cameraHeight + this.threadsY - 1) / this.threadsY, 1);
				uint[] array7 = new uint[1];
				forceWaitResultTextureToBufferBuffer.GetData(array7);
				if ((ulong)array7[0] != (ulong)((long)num12))
				{
					UnityEngine.Debug.LogError(string.Concat(new object[]
					{
						"TextureToBufferShader: Unexpected forceWaitResult value ",
						array7[0],
						", should be ",
						num12
					}));
				}
				if (this.saveCubemap && (num5 < 2 || (num5 >= 2 && num5 < 2 + this.numCirclePoints * 2) || (num5 >= leftRightPhaseEnd && num5 < leftRightPhaseEnd + this.numCirclePoints * 2)))
				{
					cameraPixelsBuffer.GetData(this.cameraPixels);
					if (this.cameraPixels[cameraPixelsBuffer.count - 1] != 1419455993U)
					{
						CapturePanorama.ReportOutOfGraphicsMemory();
					}
					this.SaveCubemapImage(this.cameraPixels, filenameBase, suffix, imagePath, saveCubemapImageNum, writeIdx);
					saveCubemapImageNum++;
				}
				writeIdx++;
				if (writeIdx >= cameraPixelsBufferNumTextures)
				{
					writeIdx = 2;
				}
				if (this.captureStereoscopic && this.usingGpuTransform && (num5 - 2 + 1) % 2 == 0 && (circlePointsRendered - nextCirclePointStart >= circlePointCircularBufferSize || num5 + 1 == 2 + (ilimit - 2) / 2 || num5 + 1 == ilimit))
				{
					num12 = 2000000 + num5;
					this.convertPanoramaStereoShader.SetInt("forceWaitValue", num12);
					this.convertPanoramaStereoShader.SetInt("leftRightPass", (num5 >= leftRightPhaseEnd) ? 0 : 1);
					this.convertPanoramaStereoShader.SetInt("circlePointStart", nextCirclePointStart);
					this.convertPanoramaStereoShader.SetInt("circlePointEnd", (cameraPixelsBufferNumTextures >= this.numCameras) ? (circlePointsRendered + 1) : circlePointsRendered);
					this.convertPanoramaStereoShader.SetInt("circlePointCircularBufferStart", nextCirclePointCircularBufferStart);
					this.convertPanoramaStereoShader.Dispatch(this.renderStereoIdx, (this.panoramaWidth + this.threadsX - 1) / this.threadsX, (this.panoramaHeight + this.threadsY - 1) / this.threadsY, 2);
					forceWaitResultConvertPanoramaStereoBuffer.GetData(array7);
					if ((ulong)array7[0] != (ulong)((long)num12))
					{
						UnityEngine.Debug.LogError(string.Concat(new object[]
						{
							"ConvertPanoramaStereoShader: Unexpected forceWaitResult value ",
							array7[0],
							", should be ",
							num12
						}));
					}
					if (num5 + 1 == leftRightPhaseEnd)
					{
						nextCirclePointCircularBufferStart = (nextCirclePointCircularBufferStart + circlePointCircularBufferSize) % circlePointCircularBufferSize;
						nextCirclePointStart = 0;
						circlePointsRendered = 0;
					}
					else
					{
						nextCirclePointStart = circlePointsRendered - this.overlapTextures;
						nextCirclePointCircularBufferStart = (nextCirclePointCircularBufferStart + circlePointCircularBufferSize - this.overlapTextures) % circlePointCircularBufferSize;
					}
				}
				RenderTexture.active = null;
			}
			this.AfterRenderPanorama();
			this.Log("Resetting quality level");
			if (qualitySettingWasChanged)
			{
				QualitySettings.SetQualityLevel(saveQualityLevel, false);
			}
			if (this.saveCubemap || !this.usingGpuTransform)
			{
				cameraPixelsBuffer.GetData(this.cameraPixels);
				if (this.cameraPixels[cameraPixelsBuffer.count - 1] != 1419455993U)
				{
					CapturePanorama.ReportOutOfGraphicsMemory();
				}
			}
			RenderTexture.active = null;
			if (this.saveCubemap && (!this.captureStereoscopic || !this.usingGpuTransform))
			{
				for (int num13 = 0; num13 < this.numCameras; num13++)
				{
					int bufferIdx = num13;
					this.SaveCubemapImage(this.cameraPixels, filenameBase, suffix, imagePath, num13, bufferIdx);
				}
			}
			for (int j = 0; j < 2; j++)
			{
				yield return new WaitForEndOfFrame();
			}
			if (async && !this.usingGpuTransform && this.fadeDuringCapture)
			{
				yield return base.StartCoroutine(this.FadeIn(fadeControls));
			}
			<CaptureScreenshotAsyncHelper>c__AnonStoreyD.filePath = imagePath + "/" + filenameBase + suffix;
			bool producedImageSuccess = false;
			Bitmap bitmap = new Bitmap(this.panoramaWidth, this.panoramaHeight * ((!this.captureStereoscopic) ? 1 : 2), PixelFormat.Format32bppArgb);
			BitmapData bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, bitmap.PixelFormat);
			IntPtr ptr = bmpData.Scan0;
			byte[] pixelValues = new byte[Math.Abs(bmpData.Stride) * bitmap.Height];
			if (async)
			{
				yield return base.StartCoroutine(this.CubemapToEquirectangular(cameraPixelsBuffer, this.cameraPixels, convertPanoramaResultBuffer, this.cameraWidth, this.cameraHeight, pixelValues, bmpData.Stride, this.panoramaWidth, this.panoramaHeight, this.ssaaFactor, async));
			}
			else
			{
				IEnumerator enumerator = this.CubemapToEquirectangular(cameraPixelsBuffer, this.cameraPixels, convertPanoramaResultBuffer, this.cameraWidth, this.cameraHeight, pixelValues, bmpData.Stride, this.panoramaWidth, this.panoramaHeight, this.ssaaFactor, async);
				while (enumerator.MoveNext())
				{
				}
			}
			producedImageSuccess = (pixelValues[3] == byte.MaxValue);
			yield return null;
			Marshal.Copy(pixelValues, 0, ptr, pixelValues.Length);
			bitmap.UnlockBits(bmpData);
			yield return null;
			this.Log("Time to take panorama screenshot: " + (Time.realtimeSinceStartup - startTime) + " sec");
			if (producedImageSuccess)
			{
				Thread thread = new Thread(delegate()
				{
					this.Log("Saving equirectangular image");
					bitmap.Save(<CaptureScreenshotAsyncHelper>c__AnonStoreyD.filePath, this.FormatToDrawingFormat(this._imageFormat));
				});
				thread.Start();
				while (thread.ThreadState == System.Threading.ThreadState.Running)
				{
					if (async)
					{
						yield return null;
					}
					else
					{
						Thread.Sleep(0);
					}
				}
			}
			bitmap.Dispose();
			foreach (ComputeBuffer computeBuffer in new ComputeBuffer[]
			{
				convertPanoramaResultBuffer,
				cameraPixelsBuffer,
				forceWaitResultConvertPanoramaStereoBuffer,
				forceWaitResultTextureToBufferBuffer
			})
			{
				if (computeBuffer != null)
				{
					computeBuffer.Release();
				}
			}
			convertPanoramaResultBuffer = (cameraPixelsBuffer = null);
			if (async && this.usingGpuTransform && this.fadeDuringCapture)
			{
				yield return base.StartCoroutine(this.FadeIn(fadeControls));
			}
			foreach (ScreenFadeControl obj in fadeControls)
			{
				UnityEngine.Object.Destroy(obj);
			}
			fadeControls.Clear();
			if (!producedImageSuccess)
			{
				if (this.failSound != null && Camera.main != null)
				{
					this.audioSource.PlayOneShot(this.failSound);
				}
			}
			else if (this.doneSound != null && Camera.main != null)
			{
				this.audioSource.PlayOneShot(this.doneSound);
			}
			this.Capturing = false;
			yield break;
		}

		// Token: 0x06000027 RID: 39 RVA: 0x00003781 File Offset: 0x00001981
		public virtual bool OnCaptureStart()
		{
			return true;
		}

		// Token: 0x06000028 RID: 40 RVA: 0x00003784 File Offset: 0x00001984
		public virtual Camera[] GetCaptureCameras()
		{
			Camera[] allCameras = Camera.allCameras;
			List<Camera> list = new List<Camera>();
			foreach (Camera item in allCameras)
			{
				list.Add(item);
			}
			return list.ToArray();
		}

		// Token: 0x06000029 RID: 41 RVA: 0x00002973 File Offset: 0x00000B73
		public virtual void BeforeRenderPanorama()
		{
		}

		// Token: 0x0600002A RID: 42 RVA: 0x00002973 File Offset: 0x00000B73
		public virtual void AfterRenderPanorama()
		{
		}

		// Token: 0x0600002B RID: 43 RVA: 0x000037C9 File Offset: 0x000019C9
		private static void ReportOutOfGraphicsMemory()
		{
			throw new OutOfMemoryException("Exhausted graphics memory while capturing panorama. Please lower image Width");
		}

		// Token: 0x0600002C RID: 44 RVA: 0x000037D8 File Offset: 0x000019D8
		private void SaveCubemapImage(uint[] cameraPixels, string filenameBase, string suffix, string imagePath, int i, int bufferIdx)
		{
			Bitmap bitmap = new Bitmap(this.cameraWidth, this.cameraHeight, PixelFormat.Format32bppArgb);
			BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, bitmap.PixelFormat);
			IntPtr scan = bitmapData.Scan0;
			byte[] array = new byte[Math.Abs(bitmapData.Stride) * bitmap.Height];
			int stride = bitmapData.Stride;
			int height = bitmapData.Height;
			int num = bufferIdx * this.cameraWidth * this.cameraHeight;
			for (int j = 0; j < this.cameraHeight; j++)
			{
				int num2 = stride * (height - 1 - j);
				for (int k = 0; k < this.cameraWidth; k++)
				{
					uint num3 = cameraPixels[num];
					array[num2] = (byte)(num3 & 255U);
					array[num2 + 1] = (byte)(num3 >> 8 & 255U);
					array[num2 + 2] = (byte)(num3 >> 16);
					array[num2 + 3] = byte.MaxValue;
					num2 += 4;
					num++;
				}
			}
			Marshal.Copy(array, 0, scan, array.Length);
			bitmap.UnlockBits(bitmapData);
			string text;
			if (this.captureStereoscopic)
			{
				text = i.ToString();
				this.Log("Saving lightfield camera image number " + text);
			}
			else
			{
				CubemapFace cubemapFace = (CubemapFace)i;
				text = cubemapFace.ToString();
				this.Log("Saving cubemap image " + text);
			}
			string filename = string.Concat(new string[]
			{
				imagePath,
				"/",
				filenameBase,
				"_",
				text,
				suffix
			});
			bitmap.Save(filename, this.FormatToDrawingFormat(this._imageFormat));
			bitmap.Dispose();
		}

		// Token: 0x0600002D RID: 45 RVA: 0x00003998 File Offset: 0x00001B98
		private Color32 GetCameraPixelBilinear(uint[] cameraPixels, int cameraNum, float u, float v)
		{
			u *= (float)this.cameraWidth;
			v *= (float)this.cameraHeight;
			int num = (int)Math.Floor((double)u);
			int num2 = Math.Min(this.cameraWidth - 1, num + 1);
			int num3 = (int)Math.Floor((double)v);
			int num4 = Math.Min(this.cameraHeight - 1, num3 + 1);
			float t = u - (float)num;
			float t2 = v - (float)num3;
			int num5 = cameraNum * this.cameraWidth * this.cameraHeight;
			int num6 = num5 + num3 * this.cameraWidth;
			int num7 = num5 + num4 * this.cameraWidth;
			uint num8 = cameraPixels[num6 + num];
			uint num9 = cameraPixels[num6 + num2];
			uint num10 = cameraPixels[num7 + num];
			uint num11 = cameraPixels[num7 + num2];
			float num12 = Mathf.Lerp(Mathf.Lerp(num8 >> 16, num10 >> 16, t2), Mathf.Lerp(num9 >> 16, num11 >> 16, t2), t);
			float num13 = Mathf.Lerp(Mathf.Lerp(num8 >> 8 & 255U, num10 >> 8 & 255U, t2), Mathf.Lerp(num9 >> 8 & 255U, num11 >> 8 & 255U, t2), t);
			float num14 = Mathf.Lerp(Mathf.Lerp(num8 & 255U, num10 & 255U, t2), Mathf.Lerp(num9 & 255U, num11 & 255U, t2), t);
			return new UnityEngine.Color(num12 / 255f, num13 / 255f, num14 / 255f, 1f);
		}

		// Token: 0x0600002E RID: 46 RVA: 0x00003B2C File Offset: 0x00001D2C
		internal void ClearProcessQueue()
		{
			while (CapturePanorama.resizingProcessList.Count > 0)
			{
				CapturePanorama.resizingProcessList[0].WaitForExit();
				File.Delete(CapturePanorama.resizingFilenames[0]);
				CapturePanorama.resizingProcessList.RemoveAt(0);
				CapturePanorama.resizingFilenames.RemoveAt(0);
			}
		}

		// Token: 0x0600002F RID: 47 RVA: 0x00003B84 File Offset: 0x00001D84
		private IEnumerator CubemapToEquirectangular(ComputeBuffer cameraPixelsBuffer, uint[] cameraPixels, ComputeBuffer convertPanoramaResultBuffer, int cameraWidth, int cameraHeight, byte[] pixelValues, int stride, int panoramaWidth, int panoramaHeight, int ssaaFactor, bool async)
		{
			if (this.captureStereoscopic && this.usingGpuTransform)
			{
				convertPanoramaResultBuffer.GetData(this.resultPixels);
				if (this.resultPixels[convertPanoramaResultBuffer.count - 1] != 1419455993U)
				{
					CapturePanorama.ReportOutOfGraphicsMemory();
				}
				this.writeOutputPixels(pixelValues, stride, panoramaWidth, panoramaHeight * 2, panoramaHeight * 2, 0);
			}
			else if (this.captureStereoscopic && !this.usingGpuTransform)
			{
				float startTime = Time.realtimeSinceStartup;
				float processingTimePerFrame = this.cpuMillisecondsPerFrame / 1000f;
				for (int y = 0; y < panoramaHeight; y++)
				{
					for (int x = 0; x < panoramaWidth; x++)
					{
						float xcoord = (float)x / (float)panoramaWidth;
						float ycoord = (float)y / (float)panoramaHeight;
						float latitude = (ycoord - 0.5f) * 3.1415927f;
						float sinLat = Mathf.Sin(latitude);
						float cosLat = Mathf.Cos(latitude);
						float longitude = (xcoord * 2f - 1f) * 3.1415927f;
						float sinLong = Mathf.Sin(longitude);
						float cosLong = Mathf.Cos(longitude);
						float latitudeNormalized = latitude / 1.5707964f;
						float ipdScale = this.IpdScaleFunction(latitudeNormalized);
						float scaledEyeRadius = ipdScale * this.interpupillaryDistance / 2f;
						float ipdScaleLerp = 1f - ipdScale * 5f;
						UnityEngine.Color colorCap = new UnityEngine.Color(0f, 0f, 0f, 0f);
						if (ipdScaleLerp > 0f)
						{
							Vector3 vector = new Vector3(cosLat * sinLong, sinLat, cosLat * cosLong);
							float num = 1f / vector.y;
							float u = vector.x * num;
							float v = vector.z * num;
							if (u * u <= 1f && v * v <= 1f)
							{
								int cameraNum;
								if (vector.y > 0f)
								{
									cameraNum = 0;
								}
								else
								{
									u = -u;
									cameraNum = 1;
								}
								u = (u + 1f) * 0.5f;
								v = (v + 1f) * 0.5f;
								colorCap = this.GetCameraPixelBilinear(cameraPixels, cameraNum, u, v);
							}
						}
						for (int i = 0; i < 2; i++)
						{
							Vector3 vector2 = new Vector3(sinLong, 0f, cosLong);
							float num2 = 1.5707964f - Mathf.Acos(scaledEyeRadius / this.circleRadius);
							if (i == 0)
							{
								num2 = -num2;
							}
							float num3 = longitude + num2;
							if (num3 < 0f)
							{
								num3 += 6.2831855f;
							}
							if (num3 >= 6.2831855f)
							{
								num3 -= 6.2831855f;
							}
							float num4 = num3 / 6.2831855f * (float)this.numCirclePoints;
							int num5 = (int)Mathf.Floor(num4) % this.numCirclePoints;
							UnityEngine.Color a = default(UnityEngine.Color);
							UnityEngine.Color b = default(UnityEngine.Color);
							for (int j = 0; j < 2; j++)
							{
								int num6 = (j != 0) ? ((num5 + 1) % this.numCirclePoints) : num5;
								float f = 6.2831855f * (float)num6 / (float)this.numCirclePoints;
								float num7 = Mathf.Sin(f);
								float num8 = Mathf.Cos(f);
								float num9 = Mathf.Sign(vector2.x * num8 - vector2.z * num7) * Mathf.Acos(vector2.z * num8 + vector2.x * num7);
								float num10 = Mathf.Cos(num9);
								float num11 = Mathf.Sin(num9);
								int cameraNum = 2 + num6 * 2 + ((num9 < 0f) ? 0 : 1);
								float num12 = (num9 < 0f) ? this.hFovAdjust : (-this.hFovAdjust);
								float f2 = num9 + num12;
								Vector3 vector3 = new Vector3(cosLat * Mathf.Sin(f2), sinLat, cosLat * Mathf.Cos(f2));
								float u = vector3.x / vector3.z / this.tanHalfHFov;
								float v = -vector3.y / vector3.z / this.tanHalfVFov;
								if (vector3.z <= 0f || u * u > 1f || v * v > 0.9f)
								{
									cameraNum = 2 + this.numCirclePoints * 2 + num6 * 2 + ((latitude < 0f) ? 0 : 1);
									float f3 = (latitude < 0f) ? (-this.vFovAdjust) : this.vFovAdjust;
									float num13 = Mathf.Cos(f3);
									float num14 = Mathf.Sin(f3);
									vector3 = new Vector3(cosLat * num11, num13 * sinLat - cosLat * num10 * num14, num14 * sinLat + cosLat * num10 * num13);
									u = vector3.x / vector3.z / this.tanHalfHFov;
									v = -vector3.y / vector3.z / this.tanHalfVFov;
								}
								u = (u + 1f) * 0.5f;
								v = (v + 1f) * 0.5f;
								UnityEngine.Color color = this.GetCameraPixelBilinear(cameraPixels, cameraNum, u, v);
								if (j == 0)
								{
									a = color;
								}
								else
								{
									b = color;
								}
							}
							Color32 c = UnityEngine.Color.Lerp(a, b, num4 - Mathf.Floor(num4));
							if (colorCap.a > 0f && ipdScaleLerp > 0f)
							{
								c = UnityEngine.Color.Lerp(c, colorCap, ipdScaleLerp);
							}
							int num15 = stride * (y + panoramaHeight * i) + x * 4;
							pixelValues[num15] = c.b;
							pixelValues[num15 + 1] = c.g;
							pixelValues[num15 + 2] = c.r;
							pixelValues[num15 + 3] = byte.MaxValue;
						}
						if ((x & 255) == 0 && Time.realtimeSinceStartup - startTime > processingTimePerFrame)
						{
							yield return null;
							startTime = Time.realtimeSinceStartup;
						}
					}
				}
			}
			else if (!this.captureStereoscopic && this.usingGpuTransform)
			{
				int num16 = (panoramaHeight + 8 - 1) / 8;
				this.Log("Invoking GPU shader for equirectangular reprojection");
				int num17 = (int)Mathf.Floor((float)panoramaHeight * 0.25f);
				int num18 = (int)Mathf.Ceil((float)panoramaHeight * 0.75f);
				for (int k = 0; k < 8; k++)
				{
					int num19 = k * num16;
					int num20 = Math.Min(num19 + num16, panoramaHeight);
					this.convertPanoramaShader.SetInt("startY", k * num16);
					this.convertPanoramaShader.SetInt("sliceHeight", num20 - num19);
					if (num20 <= num17)
					{
						this.convertPanoramaShader.Dispatch(this.convertPanoramaYNegativeKernelIdx, (panoramaWidth + this.threadsX - 1) / this.threadsX, (num16 + this.threadsY - 1) / this.threadsY, 1);
					}
					else if (num19 >= num18)
					{
						this.convertPanoramaShader.Dispatch(this.convertPanoramaYPositiveKernelIdx, (panoramaWidth + this.threadsX - 1) / this.threadsX, (num16 + this.threadsY - 1) / this.threadsY, 1);
					}
					else
					{
						this.convertPanoramaShader.Dispatch(this.convertPanoramaKernelIdx, (panoramaWidth + this.threadsX - 1) / this.threadsX, (panoramaHeight + this.threadsY - 1) / this.threadsY, 1);
					}
					convertPanoramaResultBuffer.GetData(this.resultPixels);
					if (this.resultPixels[convertPanoramaResultBuffer.count - 1] != 1419455993U)
					{
						CapturePanorama.ReportOutOfGraphicsMemory();
					}
					this.writeOutputPixels(pixelValues, stride, panoramaWidth, num16, panoramaHeight, num19);
				}
			}
			else if (async)
			{
				yield return base.StartCoroutine(this.CubemapToEquirectangularCpu(cameraPixels, cameraWidth, cameraHeight, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, async));
			}
			else
			{
				IEnumerator enumerator = this.CubemapToEquirectangularCpu(cameraPixels, cameraWidth, cameraHeight, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, async);
				while (enumerator.MoveNext())
				{
				}
			}
			yield break;
		}

		// Token: 0x06000030 RID: 48 RVA: 0x00003BF0 File Offset: 0x00001DF0
		private void writeOutputPixels(byte[] pixelValues, int stride, int bitmapWidth, int inHeight, int outHeight, int yStart)
		{
			int num = 0;
			int num2 = yStart;
			while (num2 < yStart + inHeight && num2 < outHeight)
			{
				int num3 = stride * num2;
				for (int i = 0; i < bitmapWidth; i++)
				{
					uint num4 = this.resultPixels[num];
					pixelValues[num3] = (byte)(num4 >> 0 & 255U);
					pixelValues[num3 + 1] = (byte)(num4 >> 8 & 255U);
					pixelValues[num3 + 2] = (byte)(num4 >> 16 & 255U);
					pixelValues[num3 + 3] = byte.MaxValue;
					num3 += 4;
					num++;
				}
				num2++;
			}
		}

		// Token: 0x06000031 RID: 49 RVA: 0x00003C80 File Offset: 0x00001E80
		private IEnumerator CubemapToEquirectangularCpu(uint[] cameraPixels, int cameraWidth, int cameraHeight, byte[] pixelValues, int stride, int panoramaWidth, int panoramaHeight, int ssaaFactor, bool async)
		{
			this.Log("Converting to equirectangular");
			yield return null;
			float startTime = Time.realtimeSinceStartup;
			float processingTimePerFrame = this.cpuMillisecondsPerFrame / 1000f;
			float maxWidth = 1f - 1f / (float)cameraWidth;
			float maxHeight = 1f - 1f / (float)cameraHeight;
			int numPixelsAveraged = ssaaFactor * ssaaFactor;
			int endYPositive = (int)Mathf.Floor((float)panoramaHeight * 0.25f);
			int startYNegative = (int)Mathf.Ceil((float)panoramaHeight * 0.75f);
			int endTopMixedRegion = (int)Mathf.Ceil((float)panoramaHeight * 0.30408698f);
			int startBottomMixedRegion = (int)Mathf.Floor((float)panoramaHeight * 0.695913f);
			int startXNegative = (int)Mathf.Ceil((float)panoramaWidth * 1f / 8f);
			int endXNegative = (int)Mathf.Floor((float)panoramaWidth * 3f / 8f);
			int startZPositive = (int)Mathf.Ceil((float)panoramaWidth * 3f / 8f);
			int endZPositive = (int)Mathf.Floor((float)panoramaWidth * 5f / 8f);
			int startXPositive = (int)Mathf.Ceil((float)panoramaWidth * 5f / 8f);
			int endXPositive = (int)Mathf.Floor((float)panoramaWidth * 7f / 8f);
			int startZNegative = (int)Mathf.Ceil((float)panoramaWidth * 7f / 8f);
			int endZNegative = (int)Mathf.Floor((float)panoramaWidth * 1f / 8f);
			if (async)
			{
				yield return base.StartCoroutine(this.CubemapToEquirectangularCpuPositiveY(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, numPixelsAveraged, 0, 0, panoramaWidth, endYPositive));
				yield return base.StartCoroutine(this.CubemapToEquirectangularCpuNegativeY(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, numPixelsAveraged, 0, startYNegative, panoramaWidth, panoramaHeight));
				yield return base.StartCoroutine(this.CubemapToEquirectangularCpuPositiveX(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, numPixelsAveraged, startXPositive, endTopMixedRegion, endXPositive, startBottomMixedRegion));
				yield return base.StartCoroutine(this.CubemapToEquirectangularCpuNegativeX(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, numPixelsAveraged, startXNegative, endTopMixedRegion, endXNegative, startBottomMixedRegion));
				yield return base.StartCoroutine(this.CubemapToEquirectangularCpuPositiveZ(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, numPixelsAveraged, startZPositive, endTopMixedRegion, endZPositive, startBottomMixedRegion));
				yield return base.StartCoroutine(this.CubemapToEquirectangularCpuNegativeZ(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, numPixelsAveraged, startZNegative, endTopMixedRegion, panoramaWidth, startBottomMixedRegion));
				yield return base.StartCoroutine(this.CubemapToEquirectangularCpuNegativeZ(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, numPixelsAveraged, 0, endTopMixedRegion, endZNegative, startBottomMixedRegion));
				yield return base.StartCoroutine(this.CubemapToEquirectangularCpuGeneralCase(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, maxWidth, maxHeight, numPixelsAveraged, 0, endYPositive, panoramaWidth, endTopMixedRegion));
				yield return base.StartCoroutine(this.CubemapToEquirectangularCpuGeneralCase(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, maxWidth, maxHeight, numPixelsAveraged, 0, startBottomMixedRegion, panoramaWidth, startYNegative));
				if (endZNegative < startXNegative)
				{
					yield return base.StartCoroutine(this.CubemapToEquirectangularCpuGeneralCase(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, maxWidth, maxHeight, numPixelsAveraged, endZNegative, endTopMixedRegion, startXNegative, startBottomMixedRegion));
				}
				if (endXNegative < startZPositive)
				{
					yield return base.StartCoroutine(this.CubemapToEquirectangularCpuGeneralCase(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, maxWidth, maxHeight, numPixelsAveraged, endXNegative, endTopMixedRegion, startZPositive, startBottomMixedRegion));
				}
				if (endZPositive < startXPositive)
				{
					yield return base.StartCoroutine(this.CubemapToEquirectangularCpuGeneralCase(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, maxWidth, maxHeight, numPixelsAveraged, endZPositive, endTopMixedRegion, startXPositive, startBottomMixedRegion));
				}
				if (endXPositive < startZNegative)
				{
					yield return base.StartCoroutine(this.CubemapToEquirectangularCpuGeneralCase(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, maxWidth, maxHeight, numPixelsAveraged, endXPositive, endTopMixedRegion, startZNegative, startBottomMixedRegion));
				}
			}
			else
			{
				IEnumerator enumerator = this.CubemapToEquirectangularCpuPositiveY(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, numPixelsAveraged, 0, 0, panoramaWidth, endYPositive);
				while (enumerator.MoveNext())
				{
				}
				enumerator = this.CubemapToEquirectangularCpuNegativeY(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, numPixelsAveraged, 0, startYNegative, panoramaWidth, panoramaHeight);
				while (enumerator.MoveNext())
				{
				}
				enumerator = this.CubemapToEquirectangularCpuPositiveX(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, numPixelsAveraged, startXPositive, endTopMixedRegion, endXPositive, startBottomMixedRegion);
				while (enumerator.MoveNext())
				{
				}
				enumerator = this.CubemapToEquirectangularCpuNegativeX(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, numPixelsAveraged, startXNegative, endTopMixedRegion, endXNegative, startBottomMixedRegion);
				while (enumerator.MoveNext())
				{
				}
				enumerator = this.CubemapToEquirectangularCpuPositiveZ(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, numPixelsAveraged, startZPositive, endTopMixedRegion, endZPositive, startBottomMixedRegion);
				while (enumerator.MoveNext())
				{
				}
				enumerator = this.CubemapToEquirectangularCpuNegativeZ(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, numPixelsAveraged, startZNegative, endTopMixedRegion, panoramaWidth, startBottomMixedRegion);
				while (enumerator.MoveNext())
				{
				}
				enumerator = this.CubemapToEquirectangularCpuNegativeZ(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, numPixelsAveraged, 0, endTopMixedRegion, endZNegative, startBottomMixedRegion);
				while (enumerator.MoveNext())
				{
				}
				enumerator = this.CubemapToEquirectangularCpuGeneralCase(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, maxWidth, maxHeight, numPixelsAveraged, 0, endYPositive, panoramaWidth, endTopMixedRegion);
				while (enumerator.MoveNext())
				{
				}
				enumerator = this.CubemapToEquirectangularCpuGeneralCase(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, maxWidth, maxHeight, numPixelsAveraged, 0, startBottomMixedRegion, panoramaWidth, startYNegative);
				while (enumerator.MoveNext())
				{
				}
				if (endZNegative < startXNegative)
				{
					enumerator = this.CubemapToEquirectangularCpuGeneralCase(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, maxWidth, maxHeight, numPixelsAveraged, endZNegative, endTopMixedRegion, startXNegative, startBottomMixedRegion);
					while (enumerator.MoveNext())
					{
					}
				}
				if (endXNegative < startZPositive)
				{
					enumerator = this.CubemapToEquirectangularCpuGeneralCase(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, maxWidth, maxHeight, numPixelsAveraged, endXNegative, endTopMixedRegion, startZPositive, startBottomMixedRegion);
					while (enumerator.MoveNext())
					{
					}
				}
				if (endZPositive < startXPositive)
				{
					enumerator = this.CubemapToEquirectangularCpuGeneralCase(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, maxWidth, maxHeight, numPixelsAveraged, endZPositive, endTopMixedRegion, startXPositive, startBottomMixedRegion);
					while (enumerator.MoveNext())
					{
					}
				}
				if (endXPositive < startZNegative)
				{
					enumerator = this.CubemapToEquirectangularCpuGeneralCase(cameraPixels, pixelValues, stride, panoramaWidth, panoramaHeight, ssaaFactor, startTime, processingTimePerFrame, maxWidth, maxHeight, numPixelsAveraged, endXPositive, endTopMixedRegion, startZNegative, startBottomMixedRegion);
					while (enumerator.MoveNext())
					{
					}
				}
			}
			yield return null;
			yield break;
		}

		// Token: 0x06000032 RID: 50 RVA: 0x00003CE0 File Offset: 0x00001EE0
		private IEnumerator CubemapToEquirectangularCpuPositiveY(uint[] cameraPixels, byte[] pixelValues, int stride, int panoramaWidth, int panoramaHeight, int ssaaFactor, float startTime, float processingTimePerFrame, int numPixelsAveraged, int startX, int startY, int endX, int endY)
		{
			for (int y = startY; y < endY; y++)
			{
				for (int x = startX; x < endX; x++)
				{
					int rTotal = 0;
					int gTotal = 0;
					int bTotal = 0;
					int aTotal = 0;
					for (int i = y * ssaaFactor; i < (y + 1) * ssaaFactor; i++)
					{
						for (int j = x * ssaaFactor; j < (x + 1) * ssaaFactor; j++)
						{
							float num = (float)j / (float)(panoramaWidth * ssaaFactor);
							float num2 = (float)i / (float)(panoramaHeight * ssaaFactor);
							float f = (num2 - 0.5f) * 3.1415927f;
							float f2 = (num * 2f - 1f) * 3.1415927f;
							float num3 = Mathf.Cos(f);
							Vector3 vector = new Vector3(num3 * Mathf.Sin(f2), -Mathf.Sin(f), num3 * Mathf.Cos(f2));
							float num4 = 1f / vector.y;
							float num5 = vector.x * num4;
							float num6 = vector.z * num4;
							num5 = (num5 + 1f) / 2f;
							num6 = (num6 + 1f) / 2f;
							Color32 cameraPixelBilinear = this.GetCameraPixelBilinear(cameraPixels, 2, num5, num6);
							rTotal += (int)cameraPixelBilinear.r;
							gTotal += (int)cameraPixelBilinear.g;
							bTotal += (int)cameraPixelBilinear.b;
							aTotal += (int)cameraPixelBilinear.a;
						}
					}
					int baseIdx = stride * (panoramaHeight - 1 - y) + x * 4;
					pixelValues[baseIdx] = (byte)(bTotal / numPixelsAveraged);
					pixelValues[baseIdx + 1] = (byte)(gTotal / numPixelsAveraged);
					pixelValues[baseIdx + 2] = (byte)(rTotal / numPixelsAveraged);
					pixelValues[baseIdx + 3] = (byte)(aTotal / numPixelsAveraged);
					if ((x & 255) == 0 && Time.realtimeSinceStartup - startTime > processingTimePerFrame)
					{
						yield return null;
						startTime = Time.realtimeSinceStartup;
					}
				}
			}
			yield break;
		}

		// Token: 0x06000033 RID: 51 RVA: 0x00003D60 File Offset: 0x00001F60
		private IEnumerator CubemapToEquirectangularCpuNegativeY(uint[] cameraPixels, byte[] pixelValues, int stride, int panoramaWidth, int panoramaHeight, int ssaaFactor, float startTime, float processingTimePerFrame, int numPixelsAveraged, int startX, int startY, int endX, int endY)
		{
			for (int y = startY; y < endY; y++)
			{
				for (int x = startX; x < endX; x++)
				{
					int rTotal = 0;
					int gTotal = 0;
					int bTotal = 0;
					int aTotal = 0;
					for (int i = y * ssaaFactor; i < (y + 1) * ssaaFactor; i++)
					{
						for (int j = x * ssaaFactor; j < (x + 1) * ssaaFactor; j++)
						{
							float num = (float)j / (float)(panoramaWidth * ssaaFactor);
							float num2 = (float)i / (float)(panoramaHeight * ssaaFactor);
							float f = (num2 - 0.5f) * 3.1415927f;
							float f2 = (num * 2f - 1f) * 3.1415927f;
							float num3 = Mathf.Cos(f);
							Vector3 vector = new Vector3(num3 * Mathf.Sin(f2), -Mathf.Sin(f), num3 * Mathf.Cos(f2));
							float num4 = 1f / vector.y;
							float num5 = vector.x * num4;
							float num6 = vector.z * num4;
							num5 = -num5;
							num5 = (num5 + 1f) / 2f;
							num6 = (num6 + 1f) / 2f;
							Color32 cameraPixelBilinear = this.GetCameraPixelBilinear(cameraPixels, 3, num5, num6);
							rTotal += (int)cameraPixelBilinear.r;
							gTotal += (int)cameraPixelBilinear.g;
							bTotal += (int)cameraPixelBilinear.b;
							aTotal += (int)cameraPixelBilinear.a;
						}
					}
					int baseIdx = stride * (panoramaHeight - 1 - y) + x * 4;
					pixelValues[baseIdx] = (byte)(bTotal / numPixelsAveraged);
					pixelValues[baseIdx + 1] = (byte)(gTotal / numPixelsAveraged);
					pixelValues[baseIdx + 2] = (byte)(rTotal / numPixelsAveraged);
					pixelValues[baseIdx + 3] = (byte)(aTotal / numPixelsAveraged);
					if ((x & 255) == 0 && Time.realtimeSinceStartup - startTime > processingTimePerFrame)
					{
						yield return null;
						startTime = Time.realtimeSinceStartup;
					}
				}
			}
			yield break;
		}

		// Token: 0x06000034 RID: 52 RVA: 0x00003DE0 File Offset: 0x00001FE0
		private IEnumerator CubemapToEquirectangularCpuPositiveX(uint[] cameraPixels, byte[] pixelValues, int stride, int panoramaWidth, int panoramaHeight, int ssaaFactor, float startTime, float processingTimePerFrame, int numPixelsAveraged, int startX, int startY, int endX, int endY)
		{
			for (int y = startY; y < endY; y++)
			{
				for (int x = startX; x < endX; x++)
				{
					int rTotal = 0;
					int gTotal = 0;
					int bTotal = 0;
					int aTotal = 0;
					for (int i = y * ssaaFactor; i < (y + 1) * ssaaFactor; i++)
					{
						for (int j = x * ssaaFactor; j < (x + 1) * ssaaFactor; j++)
						{
							float num = (float)j / (float)(panoramaWidth * ssaaFactor);
							float num2 = (float)i / (float)(panoramaHeight * ssaaFactor);
							float f = (num2 - 0.5f) * 3.1415927f;
							float f2 = (num * 2f - 1f) * 3.1415927f;
							float num3 = Mathf.Cos(f);
							Vector3 vector = new Vector3(num3 * Mathf.Sin(f2), -Mathf.Sin(f), num3 * Mathf.Cos(f2));
							float num4 = 1f / vector.x;
							float num5 = -vector.z * num4;
							float num6 = vector.y * num4;
							num6 = -num6;
							num5 = (num5 + 1f) / 2f;
							num6 = (num6 + 1f) / 2f;
							Color32 cameraPixelBilinear = this.GetCameraPixelBilinear(cameraPixels, 0, num5, num6);
							rTotal += (int)cameraPixelBilinear.r;
							gTotal += (int)cameraPixelBilinear.g;
							bTotal += (int)cameraPixelBilinear.b;
							aTotal += (int)cameraPixelBilinear.a;
						}
					}
					int baseIdx = stride * (panoramaHeight - 1 - y) + x * 4;
					pixelValues[baseIdx] = (byte)(bTotal / numPixelsAveraged);
					pixelValues[baseIdx + 1] = (byte)(gTotal / numPixelsAveraged);
					pixelValues[baseIdx + 2] = (byte)(rTotal / numPixelsAveraged);
					pixelValues[baseIdx + 3] = (byte)(aTotal / numPixelsAveraged);
					if ((x & 255) == 0 && Time.realtimeSinceStartup - startTime > processingTimePerFrame)
					{
						yield return null;
						startTime = Time.realtimeSinceStartup;
					}
				}
			}
			yield break;
		}

		// Token: 0x06000035 RID: 53 RVA: 0x00003E60 File Offset: 0x00002060
		private IEnumerator CubemapToEquirectangularCpuNegativeX(uint[] cameraPixels, byte[] pixelValues, int stride, int panoramaWidth, int panoramaHeight, int ssaaFactor, float startTime, float processingTimePerFrame, int numPixelsAveraged, int startX, int startY, int endX, int endY)
		{
			for (int y = startY; y < endY; y++)
			{
				for (int x = startX; x < endX; x++)
				{
					int rTotal = 0;
					int gTotal = 0;
					int bTotal = 0;
					int aTotal = 0;
					for (int i = y * ssaaFactor; i < (y + 1) * ssaaFactor; i++)
					{
						for (int j = x * ssaaFactor; j < (x + 1) * ssaaFactor; j++)
						{
							float num = (float)j / (float)(panoramaWidth * ssaaFactor);
							float num2 = (float)i / (float)(panoramaHeight * ssaaFactor);
							float f = (num2 - 0.5f) * 3.1415927f;
							float f2 = (num * 2f - 1f) * 3.1415927f;
							float num3 = Mathf.Cos(f);
							Vector3 vector = new Vector3(num3 * Mathf.Sin(f2), -Mathf.Sin(f), num3 * Mathf.Cos(f2));
							float num4 = 1f / vector.x;
							float num5 = -vector.z * num4;
							float num6 = vector.y * num4;
							num5 = (num5 + 1f) / 2f;
							num6 = (num6 + 1f) / 2f;
							Color32 cameraPixelBilinear = this.GetCameraPixelBilinear(cameraPixels, 1, num5, num6);
							rTotal += (int)cameraPixelBilinear.r;
							gTotal += (int)cameraPixelBilinear.g;
							bTotal += (int)cameraPixelBilinear.b;
							aTotal += (int)cameraPixelBilinear.a;
						}
					}
					int baseIdx = stride * (panoramaHeight - 1 - y) + x * 4;
					pixelValues[baseIdx] = (byte)(bTotal / numPixelsAveraged);
					pixelValues[baseIdx + 1] = (byte)(gTotal / numPixelsAveraged);
					pixelValues[baseIdx + 2] = (byte)(rTotal / numPixelsAveraged);
					pixelValues[baseIdx + 3] = (byte)(aTotal / numPixelsAveraged);
					if ((x & 255) == 0 && Time.realtimeSinceStartup - startTime > processingTimePerFrame)
					{
						yield return null;
						startTime = Time.realtimeSinceStartup;
					}
				}
			}
			yield break;
		}

		// Token: 0x06000036 RID: 54 RVA: 0x00003EE0 File Offset: 0x000020E0
		private IEnumerator CubemapToEquirectangularCpuPositiveZ(uint[] cameraPixels, byte[] pixelValues, int stride, int panoramaWidth, int panoramaHeight, int ssaaFactor, float startTime, float processingTimePerFrame, int numPixelsAveraged, int startX, int startY, int endX, int endY)
		{
			for (int y = startY; y < endY; y++)
			{
				for (int x = startX; x < endX; x++)
				{
					int rTotal = 0;
					int gTotal = 0;
					int bTotal = 0;
					int aTotal = 0;
					for (int i = y * ssaaFactor; i < (y + 1) * ssaaFactor; i++)
					{
						for (int j = x * ssaaFactor; j < (x + 1) * ssaaFactor; j++)
						{
							float num = (float)j / (float)(panoramaWidth * ssaaFactor);
							float num2 = (float)i / (float)(panoramaHeight * ssaaFactor);
							float f = (num2 - 0.5f) * 3.1415927f;
							float f2 = (num * 2f - 1f) * 3.1415927f;
							float num3 = Mathf.Cos(f);
							Vector3 vector = new Vector3(num3 * Mathf.Sin(f2), -Mathf.Sin(f), num3 * Mathf.Cos(f2));
							float num4 = 1f / vector.z;
							float num5 = vector.x * num4;
							float num6 = vector.y * num4;
							num6 = -num6;
							num5 = (num5 + 1f) / 2f;
							num6 = (num6 + 1f) / 2f;
							Color32 cameraPixelBilinear = this.GetCameraPixelBilinear(cameraPixels, 4, num5, num6);
							rTotal += (int)cameraPixelBilinear.r;
							gTotal += (int)cameraPixelBilinear.g;
							bTotal += (int)cameraPixelBilinear.b;
							aTotal += (int)cameraPixelBilinear.a;
						}
					}
					int baseIdx = stride * (panoramaHeight - 1 - y) + x * 4;
					pixelValues[baseIdx] = (byte)(bTotal / numPixelsAveraged);
					pixelValues[baseIdx + 1] = (byte)(gTotal / numPixelsAveraged);
					pixelValues[baseIdx + 2] = (byte)(rTotal / numPixelsAveraged);
					pixelValues[baseIdx + 3] = (byte)(aTotal / numPixelsAveraged);
					if ((x & 255) == 0 && Time.realtimeSinceStartup - startTime > processingTimePerFrame)
					{
						yield return null;
						startTime = Time.realtimeSinceStartup;
					}
				}
			}
			yield break;
		}

		// Token: 0x06000037 RID: 55 RVA: 0x00003F60 File Offset: 0x00002160
		private IEnumerator CubemapToEquirectangularCpuNegativeZ(uint[] cameraPixels, byte[] pixelValues, int stride, int panoramaWidth, int panoramaHeight, int ssaaFactor, float startTime, float processingTimePerFrame, int numPixelsAveraged, int startX, int startY, int endX, int endY)
		{
			for (int y = startY; y < endY; y++)
			{
				for (int x = startX; x < endX; x++)
				{
					int rTotal = 0;
					int gTotal = 0;
					int bTotal = 0;
					int aTotal = 0;
					for (int i = y * ssaaFactor; i < (y + 1) * ssaaFactor; i++)
					{
						for (int j = x * ssaaFactor; j < (x + 1) * ssaaFactor; j++)
						{
							float num = (float)j / (float)(panoramaWidth * ssaaFactor);
							float num2 = (float)i / (float)(panoramaHeight * ssaaFactor);
							float f = (num2 - 0.5f) * 3.1415927f;
							float f2 = (num * 2f - 1f) * 3.1415927f;
							float num3 = Mathf.Cos(f);
							Vector3 vector = new Vector3(num3 * Mathf.Sin(f2), -Mathf.Sin(f), num3 * Mathf.Cos(f2));
							float num4 = 1f / vector.z;
							float num5 = vector.x * num4;
							float num6 = vector.y * num4;
							num5 = (num5 + 1f) / 2f;
							num6 = (num6 + 1f) / 2f;
							Color32 cameraPixelBilinear = this.GetCameraPixelBilinear(cameraPixels, 5, num5, num6);
							rTotal += (int)cameraPixelBilinear.r;
							gTotal += (int)cameraPixelBilinear.g;
							bTotal += (int)cameraPixelBilinear.b;
							aTotal += (int)cameraPixelBilinear.a;
						}
					}
					int baseIdx = stride * (panoramaHeight - 1 - y) + x * 4;
					pixelValues[baseIdx] = (byte)(bTotal / numPixelsAveraged);
					pixelValues[baseIdx + 1] = (byte)(gTotal / numPixelsAveraged);
					pixelValues[baseIdx + 2] = (byte)(rTotal / numPixelsAveraged);
					pixelValues[baseIdx + 3] = (byte)(aTotal / numPixelsAveraged);
					if ((x & 255) == 0 && Time.realtimeSinceStartup - startTime > processingTimePerFrame)
					{
						yield return null;
						startTime = Time.realtimeSinceStartup;
					}
				}
			}
			yield break;
		}

		// Token: 0x06000038 RID: 56 RVA: 0x00003FE0 File Offset: 0x000021E0
		private IEnumerator CubemapToEquirectangularCpuGeneralCase(uint[] cameraPixels, byte[] pixelValues, int stride, int panoramaWidth, int panoramaHeight, int ssaaFactor, float startTime, float processingTimePerFrame, float maxWidth, float maxHeight, int numPixelsAveraged, int startX, int startY, int endX, int endY)
		{
			for (int y = startY; y < endY; y++)
			{
				for (int x = startX; x < endX; x++)
				{
					int rTotal = 0;
					int gTotal = 0;
					int bTotal = 0;
					int aTotal = 0;
					for (int i = y * ssaaFactor; i < (y + 1) * ssaaFactor; i++)
					{
						for (int j = x * ssaaFactor; j < (x + 1) * ssaaFactor; j++)
						{
							float num = (float)j / (float)(panoramaWidth * ssaaFactor);
							float num2 = (float)i / (float)(panoramaHeight * ssaaFactor);
							float f = (num2 - 0.5f) * 3.1415927f;
							float f2 = (num * 2f - 1f) * 3.1415927f;
							float num3 = Mathf.Cos(f);
							Vector3 vector = new Vector3(num3 * Mathf.Sin(f2), -Mathf.Sin(f), num3 * Mathf.Cos(f2));
							float num4 = 1f / vector.y;
							float num5 = vector.x * num4;
							float num6 = vector.z * num4;
							CubemapFace cameraNum;
							if (vector.y > 0f)
							{
								cameraNum = CubemapFace.PositiveY;
							}
							else
							{
								cameraNum = CubemapFace.NegativeY;
								num5 = -num5;
							}
							if (Mathf.Abs(num5) > 1f || Mathf.Abs(num6) > 1f)
							{
								num4 = 1f / vector.x;
								num5 = -vector.z * num4;
								num6 = vector.y * num4;
								if (vector.x > 0f)
								{
									cameraNum = CubemapFace.PositiveX;
									num6 = -num6;
								}
								else
								{
									cameraNum = CubemapFace.NegativeX;
								}
							}
							if (Mathf.Abs(num5) > 1f || Mathf.Abs(num6) > 1f)
							{
								num4 = 1f / vector.z;
								num5 = vector.x * num4;
								num6 = vector.y * num4;
								if (vector.z > 0f)
								{
									cameraNum = CubemapFace.PositiveZ;
									num6 = -num6;
								}
								else
								{
									cameraNum = CubemapFace.NegativeZ;
								}
							}
							num5 = (num5 + 1f) / 2f;
							num6 = (num6 + 1f) / 2f;
							num5 = Mathf.Min(num5, maxWidth);
							num6 = Mathf.Min(num6, maxHeight);
							Color32 cameraPixelBilinear = this.GetCameraPixelBilinear(cameraPixels, (int)cameraNum, num5, num6);
							rTotal += (int)cameraPixelBilinear.r;
							gTotal += (int)cameraPixelBilinear.g;
							bTotal += (int)cameraPixelBilinear.b;
							aTotal += (int)cameraPixelBilinear.a;
						}
					}
					int baseIdx = stride * (panoramaHeight - 1 - y) + x * 4;
					pixelValues[baseIdx] = (byte)(bTotal / numPixelsAveraged);
					pixelValues[baseIdx + 1] = (byte)(gTotal / numPixelsAveraged);
					pixelValues[baseIdx + 2] = (byte)(rTotal / numPixelsAveraged);
					pixelValues[baseIdx + 3] = (byte)(aTotal / numPixelsAveraged);
					if ((x & 255) == 0 && Time.realtimeSinceStartup - startTime > processingTimePerFrame)
					{
						yield return null;
						startTime = Time.realtimeSinceStartup;
					}
				}
			}
			yield break;
		}

		// Token: 0x06000039 RID: 57 RVA: 0x00004070 File Offset: 0x00002270
		public void SetImageFormat(int value)
		{
			if (value != 1)
			{
				if (value != 2)
				{
					this._imageFormat = CapturePanorama.ImageFormat.JPEG;
				}
				else
				{
					this._imageFormat = CapturePanorama.ImageFormat.PNG;
				}
			}
			else
			{
				this._imageFormat = CapturePanorama.ImageFormat.BMP;
			}
		}

		// Token: 0x0600003A RID: 58 RVA: 0x000040AC File Offset: 0x000022AC
		public void SetImageWidth(int value)
		{
			switch (value)
			{
			case 1:
				this.panoramaWidth = 2048;
				break;
			case 2:
				this.panoramaWidth = 4096;
				break;
			case 3:
				this.panoramaWidth = 8192;
				break;
			default:
				this.panoramaWidth = 1024;
				break;
			}
		}

		// Token: 0x0600003B RID: 59 RVA: 0x00004114 File Offset: 0x00002314
		public void SetAntiAliasing(int value)
		{
			switch (value)
			{
			case 1:
				this._antiAliasing = CapturePanorama.AntiAliasing._2;
				break;
			case 2:
				this._antiAliasing = CapturePanorama.AntiAliasing._4;
				break;
			case 3:
				this._antiAliasing = CapturePanorama.AntiAliasing._8;
				break;
			default:
				this._antiAliasing = CapturePanorama.AntiAliasing._1;
				break;
			}
		}

		// Token: 0x0600003C RID: 60 RVA: 0x0000416A File Offset: 0x0000236A
		public void UseGpu(bool value)
		{
			this.useGpuTransform = value;
		}

		// Token: 0x0600003D RID: 61 RVA: 0x00004173 File Offset: 0x00002373
		public void UseFade(bool value)
		{
			this.fadeDuringCapture = value;
		}

		// Token: 0x0600003E RID: 62 RVA: 0x0000417C File Offset: 0x0000237C
		public int GetImageFormat()
		{
			CapturePanorama.ImageFormat imageFormat = this._imageFormat;
			if (imageFormat == CapturePanorama.ImageFormat.BMP)
			{
				return 1;
			}
			if (imageFormat != CapturePanorama.ImageFormat.PNG)
			{
				return 0;
			}
			return 2;
		}

		// Token: 0x0600003F RID: 63 RVA: 0x000041A8 File Offset: 0x000023A8
		public int GetImageWidth()
		{
			int num = this.panoramaWidth;
			if (num == 2048)
			{
				return 1;
			}
			if (num == 4096)
			{
				return 2;
			}
			if (num != 8192)
			{
				return 0;
			}
			return 3;
		}

		// Token: 0x06000040 RID: 64 RVA: 0x000041EC File Offset: 0x000023EC
		public int GetAntiAliasing()
		{
			CapturePanorama.AntiAliasing antiAliasing = this._antiAliasing;
			switch (antiAliasing)
			{
			case CapturePanorama.AntiAliasing._2:
				return 1;
			default:
				if (antiAliasing != CapturePanorama.AntiAliasing._8)
				{
					return 0;
				}
				return 3;
			case CapturePanorama.AntiAliasing._4:
				return 2;
			}
		}

		// Token: 0x0400000A RID: 10
		private string panoramaName;

		// Token: 0x0400000B RID: 11
		private string qualitySetting;

		// Token: 0x0400000C RID: 12
		private bool captureStereoscopic;

		// Token: 0x0400000D RID: 13
		private float interpupillaryDistance = 0.0635f;

		// Token: 0x0400000E RID: 14
		private int numCirclePoints = 128;

		// Token: 0x0400000F RID: 15
		private int ssaaFactor = 1;

		// Token: 0x04000010 RID: 16
		private string saveImagePath = string.Empty;

		// Token: 0x04000011 RID: 17
		private bool saveCubemap;

		// Token: 0x04000012 RID: 18
		private bool useDefaultOrientation;

		// Token: 0x04000013 RID: 19
		private float cpuMillisecondsPerFrame = 8.333333f;

		// Token: 0x04000014 RID: 20
		private float fadeTime = 0.25f;

		// Token: 0x04000015 RID: 21
		public AudioClip startSound;

		// Token: 0x04000016 RID: 22
		public AudioClip doneSound;

		// Token: 0x04000017 RID: 23
		public AudioClip failSound;

		// Token: 0x04000018 RID: 24
		public UnityEngine.Color fadeColor = new UnityEngine.Color(0f, 0f, 0f, 1f);

		// Token: 0x04000019 RID: 25
		public Material fadeMaterial;

		// Token: 0x0400001A RID: 26
		public ComputeShader convertPanoramaShader;

		// Token: 0x0400001B RID: 27
		public ComputeShader convertPanoramaStereoShader;

		// Token: 0x0400001C RID: 28
		public ComputeShader textureToBufferShader;

		// Token: 0x0400001D RID: 29
		private CapturePanorama.ImageFormat _imageFormat;

		// Token: 0x0400001E RID: 30
		private int panoramaWidth;

		// Token: 0x0400001F RID: 31
		private CapturePanorama.AntiAliasing _antiAliasing = CapturePanorama.AntiAliasing._1;

		// Token: 0x04000020 RID: 32
		private bool useGpuTransform;

		// Token: 0x04000021 RID: 33
		private bool fadeDuringCapture;

		// Token: 0x04000022 RID: 34
		private GameObject[] camGos;

		// Token: 0x04000023 RID: 35
		private Camera cam;

		// Token: 0x04000024 RID: 36
		private ImageEffectCopyCamera copyCameraScript;

		// Token: 0x04000025 RID: 37
		private bool usingGpuTransform;

		// Token: 0x04000026 RID: 38
		private CubemapFace[] faces;

		// Token: 0x04000027 RID: 39
		private int panoramaHeight;

		// Token: 0x04000028 RID: 40
		private int cameraWidth;

		// Token: 0x04000029 RID: 41
		private int cameraHeight;

		// Token: 0x0400002A RID: 42
		private RenderTexture cubemapRenderTexture;

		// Token: 0x0400002B RID: 43
		private Texture2D forceWaitTexture;

		// Token: 0x0400002C RID: 44
		private int convertPanoramaKernelIdx = -1;

		// Token: 0x0400002D RID: 45
		private int convertPanoramaYPositiveKernelIdx = -1;

		// Token: 0x0400002E RID: 46
		private int convertPanoramaYNegativeKernelIdx = -1;

		// Token: 0x0400002F RID: 47
		private int textureToBufferIdx = -1;

		// Token: 0x04000030 RID: 48
		private int renderStereoIdx = -1;

		// Token: 0x04000031 RID: 49
		private int[] convertPanoramaKernelIdxs;

		// Token: 0x04000032 RID: 50
		private byte[] imageFileBytes;

		// Token: 0x04000033 RID: 51
		private int frameNumber;

		// Token: 0x04000034 RID: 52
		private const int ResultBufferSlices = 8;

		// Token: 0x04000035 RID: 53
		private float hFov = -1f;

		// Token: 0x04000036 RID: 54
		private float vFov = -1f;

		// Token: 0x04000037 RID: 55
		private float hFovAdjustDegrees = -1f;

		// Token: 0x04000038 RID: 56
		private float vFovAdjustDegrees = -1f;

		// Token: 0x04000039 RID: 57
		private float circleRadius = -1f;

		// Token: 0x0400003A RID: 58
		private int threadsX = 32;

		// Token: 0x0400003B RID: 59
		private int threadsY = 32;

		// Token: 0x0400003C RID: 60
		private int numCameras;

		// Token: 0x0400003D RID: 61
		private const int CamerasPerCirclePoint = 4;

		// Token: 0x0400003E RID: 62
		private uint[] cameraPixels;

		// Token: 0x0400003F RID: 63
		private uint[] resultPixels;

		// Token: 0x04000040 RID: 64
		private float tanHalfHFov;

		// Token: 0x04000041 RID: 65
		private float tanHalfVFov;

		// Token: 0x04000042 RID: 66
		private float hFovAdjust;

		// Token: 0x04000043 RID: 67
		private float vFovAdjust;

		// Token: 0x04000044 RID: 68
		private int overlapTextures;

		// Token: 0x04000045 RID: 69
		private bool initializeFailed = true;

		// Token: 0x04000046 RID: 70
		private AudioSource audioSource;

		// Token: 0x04000047 RID: 71
		private bool enableDebugging;

		// Token: 0x04000048 RID: 72
		private const uint BufferSentinelValue = 1419455993U;

		// Token: 0x04000049 RID: 73
		private int lastConfiguredPanoramaWidth;

		// Token: 0x0400004A RID: 74
		private int lastConfiguredNumCirclePoints;

		// Token: 0x0400004B RID: 75
		private int lastConfiguredSsaaFactor;

		// Token: 0x0400004C RID: 76
		private float lastConfiguredInterpupillaryDistance;

		// Token: 0x0400004D RID: 77
		private bool lastConfiguredCaptureStereoscopic;

		// Token: 0x0400004E RID: 78
		private bool lastConfiguredSaveCubemap;

		// Token: 0x0400004F RID: 79
		private bool lastConfiguredUseGpuTransform;

		// Token: 0x04000050 RID: 80
		private CapturePanorama.AntiAliasing lastConfiguredAntiAliasing = CapturePanorama.AntiAliasing._1;

		// Token: 0x04000051 RID: 81
		private static CapturePanorama instance;

		// Token: 0x04000052 RID: 82
		internal bool Capturing;

		// Token: 0x04000053 RID: 83
		private static List<Process> resizingProcessList = new List<Process>();

		// Token: 0x04000054 RID: 84
		private static List<string> resizingFilenames = new List<string>();

		// Token: 0x02000005 RID: 5
		public enum ImageFormat
		{
			// Token: 0x04000056 RID: 86
			PNG,
			// Token: 0x04000057 RID: 87
			JPEG,
			// Token: 0x04000058 RID: 88
			BMP
		}

		// Token: 0x02000006 RID: 6
		public enum AntiAliasing
		{
			// Token: 0x0400005A RID: 90
			_1 = 1,
			// Token: 0x0400005B RID: 91
			_2,
			// Token: 0x0400005C RID: 92
			_4 = 4,
			// Token: 0x0400005D RID: 93
			_8 = 8
		}
	}
}
